//
//  LeftViewController.m
//  Delicious2
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "LeftViewController.h"

@interface LeftViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation LeftViewController

- (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //背景图片
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageV.image = [UIImage imageNamed:@"ImageBack"];
    imageV.userInteractionEnabled = YES;
    [self.view addSubview:imageV];
    
    [self creatTableView];
    
    self.dataSource = [NSArray arrayWithObjects:@"group", @"cooking", @"brand", @"restaurant", @"season", nil];
}

#pragma mark - 建立tableView
- (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, HEIGHT / 4, 250, HEIGHT / 4 * 3) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCellIdentifier"];
    
    [self.view addSubview: self.tableView];
}

#pragma mark - tableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCellIdentifier"];
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    
    switch (indexPath.row) {
        case 0:
            cell.imageView.image = [UIImage imageNamed:@"ImageKind"];
            cell.textLabel.text = @"类别";
            break;
        case 1:
            cell.imageView.image = [UIImage imageNamed:@"ImageCook"];
            cell.textLabel.text = @"烹饪方式";
            break;
        case 2:
            cell.imageView.image = [UIImage imageNamed:@"ImageLabel"];
            cell.textLabel.text = @"品牌";
            break;
        case 3:
            cell.imageView.image = [UIImage imageNamed:@"ImageChain"];
            cell.textLabel.text = @"连锁餐饮";
            break;
        case 4:
            cell.imageView.image = [UIImage imageNamed:@"ImageSeason"];
            cell.textLabel.text = @"季节";
            break;
            
        default:
            break;
    }
    
    cell.textLabel.textColor = [UIColor whiteColor];
    
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 30)];
    label.text = @"  食物分类";
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont boldSystemFontOfSize:18];
    
    return label;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"Jump" object:self.dataSource[indexPath.row] userInfo:nil];
}


#pragma mark - 内存泄露警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
